home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-09 | 12.4 KB | 428 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ButtonPart.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- // Modified by M.Boetcher to accept Dropped and Pasted sounds
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef BUTTONPART_H
- #include "ButtonPart.h"
- #endif
-
- #ifndef BUTTONDEF_H
- #include "ButtonDef.h"
- #endif
-
- #ifndef BUTTONSEL_H
- #include "ButtonSel.h"
- #endif
-
- #ifndef ACTIONS_H
- #include "Actions.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWPUSHBU_H
- #include "FWPushBu.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCfmRes.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWNOTIFN_H
- #include <FWNotifn.h>
- #endif
-
- #ifndef FWCLAINF_H
- #include <FWClaInf.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- // ----- Macintosh Includes -----
- #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
- #include <Sound.h>
- #endif
-
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #pragma segment ButtonPart
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- const ODValueType CButtonPart::kPartKind = kODFButtonKind;
- const ODValueType CButtonPart::kPartUserName = kODFButtonEditorUserString;
-
- //========================================================================================
- // class CButtonPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::CButtonPart
- //----------------------------------------------------------------------------------------
-
- CButtonPart::CButtonPart(ODPart* odPart) :
- FW_CPart(odPart, CButtonPart::kPartKind, CButtonPart::kPartUserName, FW_gInstance, kPartIconID),
- fAction(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::~CButtonPart
- //----------------------------------------------------------------------------------------
-
- CButtonPart::~CButtonPart()
- {
- delete fAction;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CButtonPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register our Presentation
- CButtonSelection *selection =
- new CButtonSelection(ev, this);
- RegisterPresentation(ev, kODFButtonPresentation,
- TRUE, selection);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CButtonPart::NewFrame(Environment* ev,
- ODFrame* frame,
- FW_CPresentation* presentation,
- FW_Boolean storage)
- {
- return new CButtonFrame(ev, frame, presentation, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::InternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CButtonPart::InternalizeContent(Environment *ev,
- ODStorageUnit* storage,
- FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(fAction == NULL);
-
- if (CScriptAction::IsInStorage(ev, storage))
- fAction = new CScriptAction();
- else if (CSoundAction::IsInStorage(ev, storage))
- fAction = new CSoundAction();
-
- if (fAction != NULL)
- fAction->Internalize(ev, storage);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::ExternalizeContent
- //----------------------------------------------------------------------------------------
- void CButtonPart::ExternalizeContent(Environment *ev,
- ODStorageUnit* storage,
- FW_CCloneInfo* cloneInfo)
- {
- // ----- Remove script value if exist -----
- if (storage->Exists(ev, kODPropContents, kScriptScrapKind, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kScriptScrapKind, 0, kODPosUndefined);
- storage->Remove(ev);
- }
-
- // ----- Remove sound value if exist -----
- if (storage->Exists(ev, kODPropContents, kSoundScrapKind, 0))
- {
- storage->Focus(ev, kODPropContents, kODPosUndefined, kSoundScrapKind, 0, kODPosUndefined);
- storage->Remove(ev);
- }
-
- if (fAction != NULL)
- fAction->Externalize(ev, storage);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::DoAction
- //----------------------------------------------------------------------------------------
- void CButtonPart::DoAction()
- {
- if (fAction != NULL)
- fAction->DoIt();
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonPart::SetAction
- //----------------------------------------------------------------------------------------
-
- void CButtonPart::SetAction(CAction *action)
- {
- if (action!=NULL && action!=fAction)
- {
- delete fAction;
- fAction = action;
- }
- }
-
- //========================================================================================
- // class CButtonFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::CButtonFrame
- //----------------------------------------------------------------------------------------
-
- CButtonFrame::CButtonFrame(Environment* ev,
- ODFrame* frame,
- FW_CPresentation* presentation,
- CButtonPart* part) :
- FW_CFrame(ev, frame, presentation, part),
- fButtonPart(part),
- fButton(NULL),
- fButtonId(0),
- fConnection(this),
- fButtonNotificationToken(0)
- {
- // I don't want any focus
- FW_CFocusSet focusSet(ev, part->GetSession(ev));
- SetFocusSet(ev, focusSet);
-
- fConnection.Connect();
-
- SetDroppable(ev, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::~CButtonFrame
- //----------------------------------------------------------------------------------------
-
- CButtonFrame::~CButtonFrame()
- {
- FW_CInterest interest(fButton, fButtonNotificationToken);
- fConnection.RemoveInterest(interest);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::CreateSubViews(Environment* ev)
- {
- FW_CString32 label("Button");
-
- FW_CRect frameRect = this->GetBounds(ev);
-
- fButton = new FW_CPushButton(ev, this, fButtonId, frameRect, label);
- fButton->SetNextEventHandler(ev, this);
-
- // The role of the COptionBehavior is to detect Option-Click. In this case change the focus
- // set of the frame. Having a behavior allows us to not have to subclass FW_CPushButton
- COptionBehavior* optionBehavior = new COptionBehavior(ev, this, GetPart(ev)->GetSession(ev));
- fButton->AdoptEventHandler(ev, optionBehavior);
-
- fButton->SetDefault(ev, false);
- fButtonNotificationToken = fButton->GetButtonPressedNotificationToken(ev);
- FW_CInterest interest(fButton, fButtonNotificationToken);
- fConnection.AddInterest(interest);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CButtonFrame::CanAcceptDrop(Environment* ev,
- ODDragItemIterator* dragInfo)
- {
- ODDragResult acceptDrop =
- FW_CFrame::CanAcceptDrop(ev, dragInfo);
-
- if (!acceptDrop)
- {
- for (ODStorageUnit *dragSU = dragInfo->First(ev);
- dragSU != NULL;
- dragSU = dragInfo->Next(ev))
- {
- if (CSoundAction::IsInStorage(ev, dragSU))
- return TRUE;
- if (CScriptAction::IsInStorage(ev, dragSU))
- return TRUE;
- }
- }
-
- return acceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::Draw(Environment* ev,
- ODFacet* facet,
- ODShape* invalidShape)
- {
- FW_CFacetContext fc(ev, facet, invalidShape);
-
- // Just erase and assume gadgets will draw
- FW_CRect invalidRect;
- fc.GetClipRect(invalidRect);
- FW_CRectShape::RenderRect(fc, invalidRect,
- FW_kFill, FW_kWhiteEraseInk);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::HandleNotification(
- const FW_CNotification& notification)
- {
- const FW_CButtonPressedNotification& buttonPressed =
- (FW_CButtonPressedNotification&) notification;
-
- if (buttonPressed.GetButtonId() == fButtonId)
- {
- fButtonPart->DoAction();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::AdjustSubViews
- //----------------------------------------------------------------------------------------
-
- void CButtonFrame::AdjustSubViews(Environment* ev)
- {
- FW_CRect frameRect = GetBounds(ev);
- fButton->SetSize(ev, frameRect.BotRight());
-
- // Redraw the entire frame
- this->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CButtonFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
- // When overridden, call inherited::FocusStateChanged FIRST
-
- void CButtonFrame::FocusStateChanged(Environment *ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
- {
- FW_CFrame::FocusStateChanged(ev, focus, newState, newOwner);
-
- // ----- if I just lost the selection focus then reset
- // ----- the focusset to empty
- if (!newState && focus == FW_CPart::gSelectionFocusToken)
- {
- FW_CFocusSet focusSet(ev, GetPart(ev)->GetSession(ev));
- SetFocusSet(ev, focusSet);
- }
- }
-
- //========================================================================================
- // class COptionBehavior
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::COptionBehavior
- //----------------------------------------------------------------------------------------
-
- COptionBehavior::COptionBehavior(Environment* ev, CButtonFrame* frame, ODSession* session) :
- FW_MEventHandler(ev, kNoIdentifier, NULL, TRUE, kNoPriority),
- fFrame(frame),
- fFullFocusSet(ev, session),
- fEmptyFocusSet(ev, session)
- {
- fFullFocusSet.Add(ev, FW_CPart::gKeyFocusToken);
- fFullFocusSet.Add(ev, FW_CPart::gMenuFocusToken);
- fFullFocusSet.Add(ev, FW_CPart::gSelectionFocusToken);
- fFullFocusSet.Add(ev, FW_CPart::gClipboardFocusToken);
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::~COptionBehavior
- //----------------------------------------------------------------------------------------
-
- COptionBehavior::~COptionBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean COptionBehavior::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean optionPressed = theMouseEvent.IsCopyModifier(ev);
-
- fFrame->SetFocusSet(ev, optionPressed ? fFullFocusSet : fEmptyFocusSet);
-
- return optionPressed;
- }
-